fs: avoid crash after tolerated watch ENOENT - #64821
Open
LLagoon3 wants to merge 1 commit into
Open
Conversation
Signed-off-by: LLagoon3 <115124830+LLagoon3@users.noreply.github.com>
LLagoon3
force-pushed
the
fix-fs-watch-missing-close
branch
from
July 29, 2026 15:09
a8488ea to
ea3979c
Compare
LLagoon3
marked this pull request as ready for review
July 29, 2026 16:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FSEventwrapper fromFSWatcher._handlewhen amissing path is tolerated with
throwIfNoEntry: false.test/parallel/test-fs-watch-enoent.jsto exerciseFSWatcher.close()after giving the native close callback an opportunityto run on Linux.
test/parallel/test-watch-mode-missing-env-file-signal.mjsto verifyclean SIGINT and SIGTERM exits when an optional env file is missing.
Details
On Linux,
uv_fs_event_start()returnsUV_ENOENTfor a missing path.FSEventWrap::Start()starts closing the native handle before returning thaterror. When
throwIfNoEntryis false,FSWatcher._handlepreviously kept areference to the JavaScript
FSEventwrapper. A laterFSWatcher.close()accessed that wrapper's
initializedgetter after the nativeFSEventWraphad been detached, causing the
FSEventWrap::GetInitialized()null-wrapperassertion.
Set
FSWatcher._handletonullin the toleratedUV_ENOENTbranch. This isonly a JavaScript lifecycle-state transition; it does not close the native
handle a second time or emit a
closeevent.The Linux regression test uses
common.platformTimeout(10), a non-zerodelayed timer, before calling
close(). A next tick or immediate can runbefore the native close callback and therefore would not reliably exercise
the detached-wrapper state.
The watch-mode regression test starts separate processes for SIGINT and
SIGTERM, waits for watch-mode readiness, and checks for a zero exit code, no
terminating signal, and no native assertion output. It also has readiness and
shutdown timeouts and always cleans up a child on failure.
Testing
node:24.16.0-slim,node:24.18.0-slim, andnode:26.5.0-slim.upstream/HEAD41525ab9fcb92d6f487047b024be29a1a96d639cwith exit code 134.
upstream/HEAD012ecf51d39d784f1c217f941122717688c31add.test/parallel/test-fs-watch-enoent.jsandtest/parallel/test-watch-mode-missing-env-file-signal.mjspassedindividually and for 20 repetitions each.
container using the patched build.
throwIfNoEntry, immediate-close, repeated-close,ref()/unref(), AbortSignal, and standalone watch-mode controls passed.FSEVENTWRAPinitializations and2,000 destroys.
make lintpassed.git diff --checkpassed.make -j4 testpassed on012ecf51d39d784f1c217f941122717688c31addin a clean test environment: 5,790 passed, 0 failed.
Fixes: #64819
Refs: #61870
Refs: #20985